/*!
	This module defines function for ticking time

	Company: PI Electronic (H.K.) Ltd
	Author : Terence
	Date: 21 Dec 2016
*/
#ifndef __TIME_FUN_H__
#define __TIME_FUN_H__

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "realtime.h"

#ifdef RT_DEBUG
#define DEBUG 1
#else
#define DEBUG 0
#endif
	
#define debug_print(fmt, ...) \
            do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)


#ifndef NSEC_PER_SEC
#define NSEC_PER_SEC 1000000000 //!< define 1s = 1E9 ns
#endif
//! tick current time
struct timespec tic();
// tick cuurent time and calculate the time difference with ts
/*!
	input:
		ts: time variable
		tdif: time difference between current time and ts
*/
struct timespec toc(struct timespec ts, float *tdif);

//! sem timeout is a time function for semaphore timeout
void semtimeout(struct timespec *ts,int timeout);

//! get the current time for debug message
char getlocaltime(void);

//!	normalize the time from 1E9 ns to 1s
void tsnorm(struct timespec *ts);
//!	nanosleep function
void custom_nanosleep(int nanocount);

#endif